home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr48 / 386p_200.zip / 386JOY.INC < prev    next >
Text File  |  1995-01-14  |  4KB  |  125 lines

  1. ; Joystick control module
  2. ;  <bashing mode on>
  3. ;   Grrr! Why those wimpy IBM engineers chosed a stupid analog interface ?!?!?
  4. ;   Heck! If at least they included enough hardware support this 
  5. ;   could have been a little problem, but ...argh!... 
  6. ;   I hate polling things when lots of IRQs keeps knocking on the P.I.C. !!!!
  7. ;   Of course this is the "default stick" handling code, if you plan to
  8. ;   add cooler sticks, just write a XID driver and let it take control.
  9. ; <bashing mode off>
  10. ;
  11. ; Well, this is my "safe" joystick handling code
  12. ; there are better ways to handle sticks, but i know this works on anything
  13.  
  14.  
  15. ; What is needed to read the IBM joystick port:
  16. ;1.  Trigger the joystick oneshots with an 'out' to 0x201.
  17. ;    This will set all of the joystick bits on.
  18.  
  19. ;2.  Read (in) 0x201, finding:
  20.  
  21. ;     Bit         Contents
  22. ;     0         Joystick A X coordinate
  23. ;     1         Joystick A Y coordinate
  24. ;     2         Joystick B X coordinate
  25. ;     3         Joystick B Y coordinate
  26. ;     4         Button A 1
  27. ;     5         Button A 2
  28. ;     6         Button B 1
  29. ;     7         Button B 2
  30. ;
  31. ;3.  Continue reading 0x201 until ALL oneshots return to zero
  32. ;    (i've seen lots of joystic routines that seems to miss this)
  33. ;    recording the loop during which each bit falls to zero.
  34. ;    The duration of the pulse from each oneshot may be used to
  35. ;    determine the resistive load (from 0 to 100K) from each
  36. ;    Joystick, as: Time = 24.2msec. + .011 (r) msec.
  37. ;
  38. ;4.  To do this correctly, I recommend calibrating the joystick;
  39. ;    have the user move the stick to each corner, then center it,
  40. ;    while recording the resulting values.
  41.  
  42. ; "Stick device group" indexes
  43. ; (this will be useful when i will expand joystick support
  44. ;  with "external" drivers).
  45.  
  46. ; THIS IS THE ONLY SUPPORTED STICK (for now)
  47. MAIN_JOYSTICK = 0
  48.  
  49. ; these will be supported in 386P 3.00 , but you can add support
  50. ; for it as a programming exercise (hint: use 386menu for joystick
  51. ; configuration)
  52. KEYB_JOYSTICK = 1
  53. AUXA_JOYSTICK = 2
  54. AUXB_JOYSTICK = 3
  55.  
  56.  
  57. extrn _StickName:dword
  58.         ; table of pointers (offsets) to "stick device names"
  59.         ; NULL entries means the device is not present
  60.         ; first entry  is the "main_joystick" name
  61.         ; second entry is the "keyb_joystick" name
  62.         ; and so on up to four entries
  63.  
  64. extrn _StickOK:near
  65.         ; Checks if joystick device needs to be "initialized"
  66.         ; before you can use it ( very useful with some joysticks)
  67.         ; in: esi= stick device group index
  68.         ; out: if carry clear then  joystick device doesn't need initialization
  69.  
  70. extrn _InitStick:near
  71.         ; in: esi = stick device group index
  72.         ; initializes and calibrates the sticks
  73.  
  74. extrn _ReadStick:near
  75.         ; IN:   ESI = STICK DEVICE GROUP INDEX
  76.         ; OUT:  EAX = STICK BITS for joystick 0,1
  77.         ;       EDX = STICK BITS for joystick 2,3
  78.         ;
  79.         ; AX            = STICK0 
  80.         ; EAX high word = STICK1
  81.         ; DX            = STICK2
  82.         ; EDX high word = STICK3
  83.         ; Every joystick is described by 16 bits
  84.         ; (it includes 3D motion and 3D rotation plus four buttons)
  85.         ; bit  meaning
  86.         ;   0  UP 
  87.         ;   1  DOWN 
  88.         ;   2  LEFT 
  89.         ;   3  RIGHT 
  90.         ;   4  FORWARD 
  91.         ;   5  BACKWARD
  92.         ;   6  TURN_UP      = rotate forward-->up
  93.         ;   7  TURN_DOWN    = rotate forward-->down
  94.         ;   8  TURN_LEFT    = rotate forward-->left
  95.         ;   9  TURN_RIGHT   = rotate forward-->right
  96.         ;  10  ROLL_LEFT    = rotate up-->left
  97.         ;  11  ROLL_RIGHT   = rotate up-->right
  98.         ;  12  BUTTON_0 
  99.         ;  13  BUTTON_1 
  100.         ;  14  BUTTON_2 
  101.         ;  15  BUTTON_3
  102.         
  103. J_UP        =1
  104. J_DOWN      =2
  105. J_LEFT      =4
  106. J_RIGHT     =8
  107. J_FORWARD   =16
  108. J_BACKWARD  =32
  109. J_TUP       =64
  110. J_TDOWN     =128
  111. J_TLEFT     =256
  112. J_TRIGHT    =512
  113. J_RLEFT     =1024
  114. J_RRIGHT    =2048
  115. J_B0        =4096
  116. J_B1        =8192
  117. J_B2        =16384
  118. J_B3        =32768
  119. UPPER_STICK =65536
  120.  
  121.         ; N.B. A plain ibm-compatible analog joystick supports only two buttons
  122.         ;      but because the "joystick control" routines can be overwritten
  123.         ;      by a XID module, i added entries for up to four buttons.
  124.  
  125.